package cn.gz.demo.ui;


import android.os.Build;
import android.os.Bundle;

import androidx.annotation.RequiresApi;
import androidx.core.widget.NestedScrollView;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

import cn.gz.demo.R;
import cn.gz.demo.adapter.WorkListAdapter;
import cn.gz.demo.databinding.CoordinatorScrollViewBinding;
import cn.gz.demo.ui.base.BaseActivity;
import cn.gz.demo.utils.LogUtil;
import cn.gz.demo.view.ObservableScrollView;

/**
 * @author Liuyz
 * @date 2020/5/3014:26
 */
public class CoordinatorScrollviewActivity extends BaseActivity {
    private CoordinatorScrollViewBinding binding;
    private List<String> caseList = new ArrayList<>();
    private WorkListAdapter caseAdapter;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_coordinatorlayout_scrollview);

        binding.recyclerview.setLayoutManager(new LinearLayoutManager(context));
        caseAdapter = new WorkListAdapter(context, caseList);
        binding.recyclerview.setAdapter(caseAdapter);

        for (int i = 0; i < 20; i++) {
            caseList.add("");
        }
        caseAdapter.notifyDataSetChanged();

        binding.waitScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                LogUtil.showLog("waitScrollView....scrollX....." + scrollX + "....scrollY....." + scrollY + "....oldScrollX....." + oldScrollX + "....oldScrollY....." + oldScrollY);
            }
        });

        binding.workWaitHorscrollview.setScrollViewListener(new ObservableScrollView.ScrollViewListener() {//滑动监听,获取图片
            @Override
            public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
                LogUtil.showLog("workWaitHorscrollview....x....." + x + ".... y....." + y + "....oldx....." + oldx + "....oldy....." + oldy);
                if (Math.abs(x - oldx) > 10) {
                    LogUtil.showLog("workWaitHorscrollview....进入了.....");
                    binding.workWaitHorscrollview.getParent().requestDisallowInterceptTouchEvent(false);
                } else {
                    binding.workWaitHorscrollview.getParent().requestDisallowInterceptTouchEvent(true);
                }
            }
        });
    }
}
